package com.xuankejun.view;

import java.util.List;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;

import com.xuankejun.R;
import com.xuankejun.adapter.DisciplineAdapter;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;

public class ProfessionList extends Activity {
	private ListView mList;
	private DisciplineAdapter disciplineAdapter;
//	private ImageView imageView;
//	private int image_id = 1000;
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.disciplinelist);
        mList = (ListView)findViewById(R.id.listview1);
        
        BmobQuery<ProfessionItem> query = new BmobQuery<ProfessionItem>();
        query.order("-createdAt");
//        Bundle getextras = getIntent().getExtras();
//        query.addWhereEqualTo("discipline", getextras.getString("disciplineName"));
        
        query.findObjects(this, new FindListener<ProfessionItem>() {
			
			@Override
			public void onSuccess(List<ProfessionItem> arg0) {
				// TODO Auto-generated method stub
				disciplineAdapter = new DisciplineAdapter(ProfessionList.this, arg0);
		        mList.setAdapter(disciplineAdapter);
			}
			
			@Override
			public void onError(int arg0, String arg1) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), arg1, Toast.LENGTH_LONG).show();
				return;
			}
		});
        
//        initView();
    }
	
	private void initView(){
//		LinearLayout linearLayout = (LinearLayout)findViewById(R.id.disciplineList);
//		imageView = new ImageView(this);
//		imageView.setImageResource(R.drawable.cj4);
//		imageView.setId(image_id);
//		
//		LinearLayout.LayoutParams layoutParams
//				= new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//		layoutParams.leftMargin = 0;
//		layoutParams.topMargin = 10;
//		linearLayout.addView(imageView, layoutParams);
	}
}
